package com.zzy.utils.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author kazu
 * @Date 2023/2/2 10:33
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
	@Override
	public void insertFill(MetaObject metaObject) {
		if (metaObject.hasSetter("createTime")) {
			this.setFieldValByName("createTime", new Date(), metaObject);
		}
		if (metaObject.hasSetter("updateTime")) {
			this.setFieldValByName("updateTime", new Date(), metaObject);
		}
	}
	
	@Override
	public void updateFill(MetaObject metaObject) {
		if (metaObject.hasSetter("updateTime")) {
			this.setFieldValByName("updatetime", new Date(), metaObject);
		}
	}
}
